import logging
import yaml
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from impact import platform, authorization, dashboard, admin, widget,queue

from impact.platform import util




## PAGES

class HomePage(platform.TemplateHandler):

	def __init__(self):
		self.template = "templates/index.html"

	def prepare_page(self,uctx,inputs,pagedata):
		for k in inputs:
			pagedata[str(k)] = str(inputs[k])





##URL MAPPINGS

config        = yaml.load(open('config.yaml', 'r'))
url_mappings  = [ ('/', HomePage) ]

url_mappings.extend(platform.get_url_mappings())
url_mappings.extend(dashboard.get_url_mappings())
url_mappings.extend(authorization.get_url_mappings())
url_mappings.extend(admin.get_url_mappings())
url_mappings.extend(queue.get_url_mappings())


#LOG FILTERING
if util.in_development():
	class NoGetFilter(logging.Filter):
		def filter(self, record):
			return not record.getMessage().startswith('"GET ')

	log = logging.getLogger()
	log.addFilter(NoGetFilter())

## IMPACT APP


application = webapp.WSGIApplication(url_mappings, debug=True)
widget.init(config)
authorization.init(config)
dashboard.init(config)
queue.init(config)
platform.LoginHandler.add_new_user_listener(dashboard._create_project)


def main():
	run_wsgi_app(application)

if __name__ == "__main__":
	main()

